package com.fast.fastenjoy.test.server;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

/**
 * 测试启动入口
 * @author chenliaohua
 *
 */
public class JettyServer {

	private static final int port = 8080; // 端口号
	private static final String webContext = "/fast"; // 上下文路径
	private static final String resourceBase = "./src/main/webapp"; // web工程目录

	public void startServer() {
		try {
			Server server = new Server();
			Connector connector = new SelectChannelConnector();
			connector.setPort(port);
			server.setConnectors(new Connector[] { connector });
			WebAppContext webapp = new WebAppContext();
			webapp.setContextPath(webContext);
			webapp.setClassLoader(JettyServer.class.getClassLoader());
			webapp.setResourceBase(resourceBase);
			server.setHandler(webapp);
			server.start();
			server.join();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		JettyServer server = new JettyServer();
		server.startServer();
	}

}
